package com.example.a;

 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Random;
  import java.util.Scanner;
 public class Test01 {
     public static void main(String[] args) {
         int[][] arr = new int[10000][3];
         int[] temp01 = new int[3];
         Scanner in = new Scanner(System.in);
         System.out.println("*******给小学生的自动出题系统******");
         System.out.println("请输入题量：");
         int m = in.nextInt();
         System.out.println("请选择几题一换行：");
         int n = in.nextInt();
         int x = 1, y = 0, num1, num2, cmp;
         boolean flag = false;
         for (int i = 0; i < m; i++) {
             flag = false;
             Random r = new Random();
             int temp;
             num1 = r.nextInt(100) + 1;
             num2 = r.nextInt(100) + 1;
             cmp = r.nextInt(4);
             temp01[0] = num1;
             temp01[1] = num2;
             temp01[2] = cmp;
             for (int j = 0; j < y; j++) {
                 if (arr[j] == temp01) {
                     flag = true;
                     break;
                 }
             }
             if (flag)
                 continue;
             else
             {
                 arr[y][0] = num1;
                 arr[y][1] = num2;
                 arr[y][2] = cmp;
                 y++;
                 switch (cmp) {
                     case 0://加
                         System.out.print("第" + x + "个题目：" + num1 + "+" + num2 + "=   ");
                         break;
                     case 1://减
                         if (num1 < num2) {
                             temp = num1;
                             num1 = num2;
                             num2 = temp;
                         }
                         System.out.print("第" + x + "个题目：" + num1 + "-" + num2 + "=    ");
                         break;
                     case 2://乘
                         if (num1 < num2) {
                             temp = num1;
                             num1 = num2;
                             num2 = temp;
                         }
                         while (num1 * num2 >= 100)
                             num1--;
                         System.out.print("第" + x + "个题目：" + num1 + "*" + num2 + "=    ");
                         break;
                     case 3:
                         if (num1 < num2) {
                             temp = num1;
                             num1 = num2;
                             num2 = temp;
                         }
                         while (num1 % num2 != 0)
                             num2--;
                         System.out.print("第" + x + "个题目：" + num1 + "/" + num2 + "=    ");
                         break;
                 }
                 if (x % n == 0)
                     System.out.println();
                 x++;

             }
         }
     }
 }
